//
//  NoContentView.m
//  iDeliver
//
//  Created by 蔡强 on 2017/3/27.
//  Copyright © 2017年 kuaijiankang. All rights reserved.
//

//========== 无内容占位图 ==========//

#import "NoContentView.h"


@interface NoContentView ()<UIScrollViewDelegate>

@property (nonatomic,strong) UIImageView *imageView;
@property (nonatomic,strong) UILabel *topLabel;


@end

@implementation NoContentView

#pragma mark - 构造方法

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        // UI搭建
        [self setUpUI];
    }
    return self;
}

#pragma mark - UI搭建
/** UI搭建 */
- (void)setUpUI{
    self.backgroundColor = [UIColor whiteColor];
    
    //------- 图片 -------//
    self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 150, 85)];
    self.imageView.center = CGPointMake(self.center.x, self.center.y - 50);
    [self addSubview:self.imageView];
    
    //------- 内容描述 -------//
    self.topLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.imageView.bottom + 10, self.width, 20)];
    [self addSubview:self.topLabel];
    self.topLabel.textAlignment = NSTextAlignmentCenter;
    self.topLabel.font = [UIFont systemFontOfSize:15];
    self.topLabel.textColor = [UIColor zj_colorWithHexString:@"dddddd"];
    
    //------- 提示点击重新加载 -------//
    CGFloat width = [CalculateLabelHeight CalculateLabelWidthWithString:@"重新加载" font:15 height:20].width + 18;
    self.bottomLabel = [[UILabel alloc]initWithFrame:CGRectMake((self.width - width) / 2, self.topLabel.bottom + 10, width, 20)];
    [self addSubview:self.bottomLabel];
    self.bottomLabel.userInteractionEnabled = YES;
    self.bottomLabel.textAlignment = NSTextAlignmentCenter;
    self.bottomLabel.font = [UIFont systemFontOfSize:15];
    self.bottomLabel.backgroundColor = [UIColor themeColor];
    self.bottomLabel.layer.cornerRadius = 4;
    self.bottomLabel.layer.masksToBounds = YES;
    self.bottomLabel.textColor = [UIColor whiteColor];
    
 
    
}

#pragma mark - 根据传入的值创建相应的UI
/** 根据传入的值创建相应的UI */
- (void)setType:(NSInteger)type{
    switch (type) {
            
        case NoContentTypeNetwork: // 没网
        {
            [self setImage:@"bg_nodata" topLabelText:@"网络异常" bottomLabelText:@"点击重试"];
        }
            break;
            
        case NoContentTypeNoData:
        {
            [self setImage:@"bg_nodata" topLabelText:@"没有数据" bottomLabelText:@""];
            self.bottomLabel.hidden = YES;
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - 设置图片和文字
/** 设置图片和文字 */
- (void)setImage:(NSString *)imageName topLabelText:(NSString *)topLabelText bottomLabelText:(NSString *)bottomLabelText{
    self.imageView.image = [UIImage imageNamed:imageName];
    self.topLabel.text = topLabelText;
    self.bottomLabel.text = bottomLabelText;
}

@end
